import asyncio
from playwright.async_api import async_playwright
import time

async def get_page_info():
    url = 'https://pai.crecgec.com/#/auction/auction-detail?enquiryId=1965206398526214145'

    async with async_playwright() as p:
        # 启动Chromium浏览器（无需指定路径）
        browser = await p.chromium.launch(
            headless=True,
            args=['--disable-infobars', '--no-sandbox']
        )
        page = await browser.new_page()

        # 设置用户代理和覆盖webdriver属性
        await page.set_extra_http_headers({
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
        })
        await page.evaluate('''() => {
            Object.defineProperty(navigator, 'webdriver', {get: () => false});
            window.chrome = {runtime: {}};
        }''')

        try:
            # 导航到页面并等待网络空闲
            await page.goto(url, wait_until='networkidle', timeout=60000)

            # 获取页面信息
            title = await page.title()
            html_content = await page.content()

            print(f"页面标题: {title}")
            print(f"HTML内容前500字符: {html_content[:500]}...")

        except Exception as e:
            print(f"执行异常: {e}")
        finally:
            await browser.close()


if __name__ == "__main__":
    start_time = time.perf_counter()
    asyncio.run(get_page_info())
    elapsed_time = time.perf_counter() - start_time
    print(f"整个脚本总耗时: {elapsed_time:.2f} 秒")